#include "ObjectPool.h"
#include "Log.h"
using namespace System;
using namespace System::Collections;
        
namespace GTA
{
	ObjectPool::ObjectPool(u32 objcount)
	{
		ObjectHandles = gcnew array<u32>(objcount);
		_pos = 0;
		Count = 0;
		Length = objcount;
	}

	bool ObjectPool::Add(u32 handle)
	{
		for (u32 i=0;i<Length;i++) { if (ObjectHandles[i] == handle) return false; }
		if (_pos >= Length) _pos = 0;
		ObjectHandles[_pos] = handle;
		Count++;
		_pos++;
		return true;
	}

	bool ObjectPool::Remove(u32 handle)
	{
		for (u32 i=0;i<Length;i++)
		{
			if (ObjectHandles[i] == 0) continue;
			if (ObjectHandles[i] == handle) 
			{
				ObjectHandles[i] = 0; 
				return true;
				Count--;
			};
		}
		return false;
	}
};

		